package Ms

import (
	"fmt"
	"db2s/ETL"
	"db2s/parDef"
	"strings"
)

func QueryColValManage(val any) (newVal any) {
	if val == nil || len(fmt.Sprintf("%v", val)) == 0 || strings.EqualFold(fmt.Sprintf("'%v'", val), "'<nil>'") {
		switch {
		case len(fmt.Sprintf("%v", val)) == 0:
			newVal = "<entry>" //空字符串
		case fmt.Sprintf("%v", val) == "<nil>":
			newVal = "<null>" //null
		}
		return
	} else {
		newVal = val
	}
	switch val.(type) {
	case string:
		if val == nil {
			return
		}
		switch {
		case strings.Contains(val.(string), "SRID:") && strings.Contains(val.(string), "AXIS:OGC"): //wkt模式
			//var err error
			//if newVal, err = GeomWktToJson(val); err != nil {
			//	return err
			//}
		default:
			return newVal
		}
	default:
		return newVal
	}
	return
}

func modifyGetDbQueryOptions(s ETL.InstanceActiveS, Expect string) ETL.InstanceActiveS {
	s.SqlMode = true
	s.DBType = DBType
	s.Expect = Expect
	s.GisValFunc = QueryColValManage
	return s
}

func getTableName(parameter parDef.Parameter) (tableName string) {
	return fmt.Sprintf(" %v.%v ", parameter.Object.Schema, parameter.Object.Table)
}
